<?php
/**
* handle for <fault> elements
* @author J.Ducastel <fredbird@fredbird.org>
* @version
*/
class ooXmlRpcFault{
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access public
	*/
	function ooXmlRpcFault($code=NULL,$string=NULL) {
		$this->__construct($code,$string);
	}/**/

	/**
	*
	* @access public
	*/
	function __construct($code=NULL,$string=NULL) {
		if ($code)
			$this->setCode($code);
		if ($string)
			$this->setString($string);
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* sets faultCode
	* @param int $code
	* @access public
	* @return bool
	*/
	function setCode($code) {
		if (!is_int($code))
			return false;
		$this->code=$code;
		return true;
	}/**/

	/**
	* sets faultString
	* @param string $string
	* @access public
	* @return bool
	*/
	function setString($string) {
		if (!is_string($string))
			return false;
		$this->string=$string;
		return true;
	}/**/

	/**
	* build self node and append it to parent node
	* @param ooXmlRpcDomNode &$node
	* @access public
	* @return bool
	*/
	function appendToNode(&$node) {
		if (!is_a($node,'ooxmlrpcdomnode'))
			return false;
		if (!$this->isValid())
			return false;
		// building struct value
		$data=array(
			'faultCode'=>$this->code
			,'faultString'=>$this->string
		);
		$struct=&new ooXmlRpcValue('struct',$data);
		// appending self <fault>
		$faultNode=&$node->makeChild('fault');
		// appending struct
		$struct->appendToNode($faultNode);
		return true;
	}/**/

	/**
	* check/tells if couple code/string is valid (upon types only)
	* @param
	* @access public
	* @return bool
	*/
	function isValid() {
		return (is_int($this->code) and is_string($this->string));
	}/**/

	/**
	* sets content from node
	* @param ooXmlRpcDomNode & $node
	* @access public
	* @return bool
	*/
	function setFromNode(& $node) {
		if (!is_a($node,'ooXmlRpcDomNode'))
			return false;
		// searching code
		if ($nodes=$node->getxpathnodes('child::value/struct/member[name=\'faultCode\']/value')) {
			$value=new ooxmlrpcvalue();
			$value->setfromnode($nodes[0]);
			$this->code=$value->getvalue();
		}
		// searching string
		if ($nodes=$node->getxpathnodes('child::value/struct/member[name=\'faultString\']/value')) {
			$value=new ooxmlrpcvalue();
			$value->setfromnode($nodes[0]);
			$this->string=$value->getvalue();
		}
		// echo wakaffvar($this);
		return true;
	}/**/

	/**
	*
	* @param
	* @access public
	* @return
	* /
	function () {

	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var int faultCode
	*/
	var $code;
	/**
	* @var string faultString
	*/
	var $string='';
}
?>
